/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.base.controller;

import java.util.Map;

import com.dian.common.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.dian.common.controller.AbstractController;
import com.dian.modules.base.entity.GoodsEntity;
import com.dian.modules.base.service.GoodsService;
import com.dian.common.utils.PageUtils;
import com.dian.common.utils.R;

/**
 * 商品资料表
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-06-10 19:06:22
 */
@RestController
@Api("商品资料表接口")
@RequestMapping("base/goods")
public class GoodsController extends AbstractController{
    @Autowired
    private GoodsService goodsService;

    /**
     * 商品资料表列表
     */
    @SysLog("商品资料表列表")
    @GetMapping("/list")
    @ApiOperation("商品资料表列表")
    @RequiresPermissions("base:goods:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 商品资料表信息
     */
    @SysLog("商品资料表信息")
    @ApiOperation("商品资料表信息")
    @GetMapping("/info/{id}")
    @RequiresPermissions("base:goods:info")
    public R info(@PathVariable("id") Long id){
        GoodsEntity goods = goodsService.getInfo(id);
        return R.ok().put("goods", goods);
    }

    /**
     * 商品资料表保存
     */
    @SysLog("商品资料表保存")
    @ApiOperation("商品资料表保存")
    @PostMapping("/save")
    @RequiresPermissions("base:Goods:save")
    public R save(@RequestBody GoodsEntity goods){

		goodsService.saveInfo(goods);

        return R.ok();
    }

    /**
     * 商品资料表修改
     */
    @SysLog("商品资料表修改")
    @ApiOperation("商品资料表修改")
    @PostMapping("/update")
    @RequiresPermissions("base:goods:update")
    public R update(@RequestBody GoodsEntity goods){

		goodsService.updateInfo(goods);

        return R.ok();
    }

    /**
     * 商品资料表删除
     */
    @SysLog("商品资料表删除")
    @ApiOperation("商品资料表删除")
    @GetMapping("/delete/{id}")
    @RequiresPermissions("base:goods:delete")
    public R delete(@PathVariable("id") Long id){
		goodsService.deleteInfo(id);

        return R.ok();
    }

}
